package com.eduService.Service.ServiceImpl;


import com.aliyun.vod.upload.impl.UploadVideoImpl;
import com.aliyun.vod.upload.req.UploadFileStreamRequest;
import com.aliyun.vod.upload.req.UploadStreamRequest;
import com.aliyun.vod.upload.resp.UploadStreamResponse;
import com.eduService.Service.videoService;
import com.eduService.utils.ConstantProperties;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;


@Service
public class videoServiceImpl implements videoService {

    @Override
    public String uploadVideoAliyun(MultipartFile file) {
        String originalFilename = file.getOriginalFilename();
        try{
            InputStream inputStream = file.getInputStream();
            UploadStreamRequest request = new UploadStreamRequest(ConstantProperties.KEY_ID, ConstantProperties.KEY_WORD, originalFilename, originalFilename,inputStream);
            UploadVideoImpl uploader = new UploadVideoImpl();
            UploadStreamResponse response = uploader.uploadStream(request);
            if (response.isSuccess()){
                return response.getVideoId();
            }else
            {
                //如果设置回调URL无效，不影响视频上传，可以返回VideoId同时会返回错误码。
                // 其他情况上传失败时，VideoId为空，此时需要根据返回错误码分析具体错误原因
                return  response.getVideoId();
            }
        }catch (Exception e){
            e.printStackTrace();
            return  null;
        }




    }
}
